import { Modal } from "ant-design-vue";
import { Ref } from "vue";

//公共业务方法

export interface ToggleLineOptions {
  record: any;
  tableLoading: Ref<boolean>;
  curd: any;
  reloadTable: (params?: any) => void;
}
//上线 下线
export function toggleLineByStatus(options: ToggleLineOptions) {
  Modal.confirm({
    content: `确认${options.record.status ? "下线" : "上线"}吗？`,
    okText: "确认",
    cancelText: "取消",
    async onOk() {
      options.tableLoading.value = true;
      await options.curd.update({
        id: options.record.id,
        status: options.record.status ? 0 : 1,
      });
      options.tableLoading.value = false;
      await options.reloadTable();
    },
  });
}

export function getStatusColumn() {
  return {
    title: "状态",
    dataIndex: "status",
    key: "status",
    customRender({ text }) {
      return text ? "已上线" : "已下线";
    },
  };
}

export function getOperColumn() {
  return {
    title: "操作",
    dataIndex: "oper",
    key: "oper",
  };
}
